Skip to content

Fix Vitest workspace detection and setupFiles override#1987

Closed
mohammedahmed18 wants to merge 1 commit intomainfrom
fix/vitest-workspace-setupfiles-detection
Closed

Fix Vitest workspace detection and setupFiles override#1987
mohammedahmed18 wants to merge 1 commit intomainfrom
fix/vitest-workspace-setupfiles-detection

Conversation

@mohammedahmed18
Copy link
Copy Markdown
Contributor

Summary

Fixes two related bugs in Vitest test runner that caused test failures when projects had workspace-like comments or setupFiles configured.

Bugs Fixed

1. Workspace Detection Bug

_is_vitest_workspace() was doing a simple substring search for "workspace" in config files, matching it even in comments. This caused the openclaw project to be incorrectly identified as using workspace configuration, preventing custom config creation.

2. Missing setupFiles Override

When custom config was created, it only overrode include and pool but not setupFiles. This left relative setupFiles paths from the original config active, causing resolution issues in nested directories.

Changes

vitest_runner.py:172-191

  • Improved workspace detection to use regex pattern matching for actual workspace config patterns (defineWorkspace(, workspace: [) instead of simple substring search
  • Now ignores "workspace" in comments

vitest_runner.py:235-242

  • Added setupFiles: [] override in custom config to disable setup files for Codeflash-generated tests
  • This prevents relative path resolution issues and is safe since generated tests are self-contained

Testing

Created /opt/codeflash/tests/languages/javascript/test_vitest_setupfiles_fix.py with 2 test cases that verify:

  1. Workspace detection ignores comments
  2. setupFiles override is included in custom config

Verification

After fix, the setup.ts error is gone. Tests now encounter a different error (module resolution), proving the setupFiles fix works.

Trace ID

161e21be-9306-4a4d-a9dc-978f65a1af7a

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

Two related bugs fixed:

1. **Workspace Detection Bug**: _is_vitest_workspace() was doing a simple
   substring search for "workspace" in config files, matching it even in
   comments. This caused projects to be incorrectly identified as using
   workspace configuration, preventing custom config creation.

2. **Missing setupFiles Override**: When custom config was created, it only
   overrode `include` and `pool` but not `setupFiles`. This left relative
   setupFiles paths from original config active, causing resolution issues
   in nested directories.

**Fixes Applied**:
- vitest_runner.py:172-191 - Improved workspace detection to use regex
  pattern matching for actual workspace config patterns (defineWorkspace(,
  workspace: [) instead of simple substring search. Now ignores "workspace"
  in comments.
- vitest_runner.py:235-242 - Added setupFiles: [] override in custom config
  to disable setup files for Codeflash-generated tests. This prevents
  relative path resolution issues and is safe since generated tests are
  self-contained.

**Testing**: Created test_vitest_setupfiles_fix.py with 2 test cases.

**Trace ID**: 161e21be-9306-4a4d-a9dc-978f65a1af7a

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 3, 2026

Claude finished @mohammedahmed18's task in 5m 46s —— View job


PR Review Summary

  • Triage PR size — SMALL (23 lines of production code changed)
  • Run lint/typecheck — fixed 3 issues, pushed
  • Resolve stale review threads — none found
  • Review code changes
  • Check for duplicates
  • Post summary

Prek Checks

Fixed and pushed 3 issues:

  1. import re inside function body (vitest_runner.py:178) — moved to module-level imports
  2. Ruff Q000: bad-quotes-inline-string (vitest_runner.py:181-182) — single quotes → double quotes
  3. Tests (test_vitest_setupfiles_fix.py): replaced tempfile.TemporaryDirectory() with tmp_path fixture (per repo testing conventions) and added -> None return type annotations

Prek now passes cleanly.

Code Review

The two logic changes are correct and address the root causes:

Workspace detection (vitest_runner.py:180-192): The regex approach is sound — defineWorkspace\s*\( and workspace\s*:\s*\[ are the actual Vitest workspace indicators. One minor gap: vitest.workspace.mts and vitest.workspace.mjs are not checked alongside .ts/.js, but that's an acceptable scope for this fix.

setupFiles override (vitest_runner.py:261): setupFiles: [] in the mergeConfig call is the right fix. Generated tests are self-contained, so disabling project setup files is safe and prevents relative-path resolution failures in nested directories.

No bugs, security issues, or breaking changes found.

Duplicate Detection

No duplicates detected — _is_vitest_workspace and defineWorkspace pattern are unique to vitest_runner.py.


Last updated: 2026-04-03T21:00:00Z
| Branch

@mohammedahmed18
Copy link
Copy Markdown
Contributor Author

duplicated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant